package com.lvmama.rhino.pojo.comment.Enum;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shenlinli
 * @ClassName: EnumForCategory
 * @Description: 品类枚举
 * @date 2017年9月5日 上午10:15:32
 */
public enum EnumForCategory {

    ALLS("", "0", "全部"),
    /*VST产品品类*/
    resort_hotel("1", "0", "度假酒店"),
    cruise("2", "0", "邮轮"),
    insurance("3", "0", "保险"),
    visa("4", "0", "签证"),
    tickets("5", "0", "门票"),
    attractions_tickets("11", "5", "景点门票"),
    other_ticket("12", "5", "其它票 "),
    meal_ticket("13", "5", "组合套餐票"),
    composite_products("6", "0", "组合产品"),
    liner_combination_product("8", "6", "邮轮组合产品"),
    additional_project("7", "0", "附加项目"),
    shore_tourism("9", "7", "岸上观光"),
    cruise_add_ons("10", "7", "邮轮附加项"),
    line("14", "0", "线路"),
    package_tour("15", "14", "跟团游"),
    local_tourism("16", "14", "当地游"),
    hotel_packages("17", "14", "酒店套餐"),
    traffic_X("29", "14", "交通+X"),
    custom_tourism("42", "14", "定制游"),
    free_line("18", "14", "自由行"),
    wine_scene("181", "18", "酒+景"),
    machine_wine("182", "18", "机+酒"),
    transportation_service("183", "18", "交通+服务"),
    big_traffic("19", "0", "大交通"),
    air_ticket("20", "19", "机票"),
    other_air_ticket("21", "19", "其它机票"),
    train_ticket("22", "19", "火车票"),
    other_train_tickets("23", "19", "其它火车票"),
    bus("24", "19", "巴士"),
    other_bus("25", "19", "其它巴士"),
    steamer_ticket("26", "19", "船票"),
    other_steamer_ticket("27", "19", "其它船票"),
    WIFI_card("28", "0", "WIFI/电话卡"),
    local_play("30", "0", "当地玩乐"),
    concert_tickets("31", "30", "演出票"),
    transport_interchange("41", "30", "交通接驳"),
    other("90", "0", "其它"),
    presell("99", "0", "预售");


    private String value;
    private String parentId;
    private String showName;

    private EnumForCategory(String value, String parentId, String showName) {
        this.value = value;
        this.parentId = parentId;
        this.showName = showName;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getShowName() {
        return showName;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    /**
     * @param @return 设定文件
     * @return CommonParentType[]    返回类型
     * @throws
     * @Title: geAllCategory
     * @Description:
     */
    public static EnumForCategory[] getAllCategory() {
        List<EnumForCategory> categories = new ArrayList<>();
        outer: for (EnumForCategory category : EnumForCategory.values()){
            //parentId不为0的，如果parentId为0的并且parentId下面没有值的显示
            if("0".equals(category.getParentId())){
                for (EnumForCategory cat : EnumForCategory.values()){
                    if(category.getValue().equals(cat.getParentId())){
                        continue outer;
                    }
                }
            }
            // 排除自由行
            if(!"18".equals(category.getValue())){
                categories.add(category);
            }
        }
        EnumForCategory[] enums = new EnumForCategory[categories.size()];
        return categories.toArray(enums);
    }


    /**
     * @param @param  value
     * @param @return 设定文件
     * @return String    返回类型
     * @throws
     * @Title: getCategoryShowName
     * @Description:根据品类id得到name
     */
    public static String getCategoryShowName(String value) {
        String showName = "";
        if (value != null) {
            EnumForCategory[] vSTProductsTypes = EnumForCategory.getAllCategory();
            for (EnumForCategory vSTProductTypes : vSTProductsTypes) {
                if (vSTProductTypes.getValue().equals(value)) {
                    showName = vSTProductTypes.getShowName();
                    break;
                }
            }
        }
        return showName;
    }

    /**
     * 根据value获取名称-包括父类
     * @param value
     * @return
     */
    public static String getCategoryName(String value) {
        String showName = "";
        if(StringUtils.isNotBlank(value) && !EnumForCategory.ALLS.getValue().equals(value)) {
            for (EnumForCategory vSTProductTypes : EnumForCategory.values()) {
                if (vSTProductTypes.getValue().equals(value)) {
                    showName = vSTProductTypes.getShowName();
                    break;
                }
            }
        }
        return showName;
    }

    /**
     * @param @param  showName
     * @param @return 设定文件
     * @return String    返回类型
     * @throws
     * @Title: getCategoryValueByShowName
     * @Description:根据品类name得到id
     */
    public static String getCategoryValueByShowName(String showName) {
        String value = "";
        if (showName != null) {
            EnumForCategory[] vSTProductsTypes = EnumForCategory.getAllCategory();
            for (EnumForCategory vSTProductTypes : vSTProductsTypes) {
                if (vSTProductTypes.getShowName().equals(showName)) {
                    value = vSTProductTypes.getValue();
                    break;
                }
            }
        }
        return value;
    }

}
